The present invention relates to computer compilers, and more particularly, to compilers for converting a conventional procedural program into an object class in an object-oriented language.
As computer programs have become more complex, programming languages have become xe2x80x9cobject-orientedxe2x80x9d to reduce the complexity of the programming task. In traditional computer programming, the program is divided into data and instructions that operate on the data. In object-oriented programs, structures which combine data and the code operating on that data are combined into xe2x80x9cobjectsxe2x80x9d. Manipulations of the internal data of the object are carried out by procedures in the code. These procedures are referred to as xe2x80x9cmethodsxe2x80x9d in most object-oriented languages. Objects respond to messages that specify the methods to apply to the data. However, an outside entity cannot view or change the data unless the object provides specific methods for accomplishing these functions.
One advantage of object oriented programming is its ability to reuse code and data defined for a similar object. In object-oriented systems classes of objects are linked together in a hierarchical structure. Objects in the structure that are descendent from a particular object inherit the attributes, both data and methods, of the parent class. This structure reduces the work needed to program a new task, since the programmer need only define the differences between a parent class and a new class descendent therefrom.
In addition, the programmer can override any inherited method. This feature is particularly useful in providing libraries of object classes. The author of the library provides default methods for many functions in the library. If an end user wishes to change any default, the user need only define an object that is descendent from one of the library classes and override the default method by a new method in the descendant class.
To setup an efficient object-oriented coding environment, libraries of object classes that can be used by a number of different types of users must be first generated. If the programmer had to write every object definition from scratch, the advantages of object-oriented programming would be significantly reduced. As noted above, the ability to define a new class which is identical to the parent class with specific methods of the parent class replaced by new methods defined in the new class is particularly useful in providing libraries. The author of a library can provide default methods for those methods that can be overwritten by objects descendant from a particular parent task. If the programmer wishes to change a particular default, the programmer need only define a new class descendent from the corresponding library class, and place the new methods in the new class. Any method in the new class that has the same name as a method in the library class will override that method in the library class. Thus software vendors can sell libraries that may be more easily modified than conventional code libraries. This allows the library code to be reused by a broader range of applications than the equivalent code in a conventional library scheme.
Another advantage of object-oriented code systems lies in security for those portions of the code that author does not wish to become public. In principle, one could distribute a conventional library in the form of source code. A user could then modify any of the procedures or data in the code. Such systems do not provide a convenient means for the author to allow the end user to alter parts of the code while maintaining the remainder of the source code as a trade secret. First, the library is distributed as object code. Hence, the author need not divulge any of the underlying source code even though the user has the ability to modify the code. Second, object-oriented systems provide the ability to maintain a portion of the code and data as xe2x80x9csecretxe2x80x9d. Only data that is defined to be xe2x80x9cpublicxe2x80x9d is visible to the library user. Similarly, only certain methods in the library class may be overridden. Hence, object classes provide much of the flexibility of source code while denying the end user access to the source code.
While object-oriented systems allow data and code reuse between objects, they do not provide a method of utilizing existing non-object oriented code. There is a very large existing pool of conventional programs which represent a significant investment in programming resources. Although this existing program base might be more efficiently implemented as object oriented programs, the cost of reprogramming the existing applications is, in general, too great.
At the same time, the existing code base must be updated as systems evolve. As new features are added to existing programs, it would be advantageous to be able to use object oriented coding methods. However, there is no method for easily combining a non-object oriented program with new code consisting of classes of objects.
Broadly, it is the objective of the present invention to provide an improved object-oriented compiler.
It is a further objective of the present invention to provide a compiler that can convert non-object oriented code into a class of objects.
It is a still further objective of the present invention to provide a means for incrementally evolving existing code while providing the advantages of object-oriented programming techniques.
These and other objects of the present invention will become apparent to those skilled in the art from the following detailed description of the invention and the accompanying drawings.
The present invention is a method of operating a computer to generate an object class definition from a procedural program having a main program and a plurality of procedures. Broadly, the method determines a set of procedures, including at least one procedure that is actually called by the procedural program during the execution of the main program thereof. The identity of the procedures in the set is preferably stored in the computer during the processing of the procedural program. The method generates an object definition having a main procedure or method that reproduces the behavior exhibited by the procedural program when the main method is invoked or the main procedure is executed. In addition, the present invention generates a method in the object class definition corresponding to at least one of the procedures in the set of procedures.
Embodiments of the present invention that operate on COBOL programs store the identity of the procedures in the set of procedures by storing first, second, and third names for each procedure. The first name provides the identity of the label that marks the start of the procedure, the second name is the last label within the range of the procedure, and the third name is the name of the label following the last label within the range of the procedure. Various statements in the procedural program are translated to code in the object definition. In particular, code is included in the class definition causing a transfer of control to one of the procedures in the set of procedures corresponding to each GO TO statement in the procedural program. Similarly, method terminating code is added to the object class definition for each statement in the procedural program which declares one of the third names. In addition, method header code is added to the object class definition for each statement in the procedural program which declares one of the first names or one of the third names. Also, code is added to the object class definition corresponding to each statement in the procedural program that causes the execution of one of the procedures in the set of procedures. This code invokes a corresponding method in the object class definition.